package mtm.date;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Describe a month
 * @author CondorHero89
 *
 */
public class MtmMonth {

	private Calendar calendar;
	
	/**
	 * Constructor
	 * @param month
	 * @param year
	 */
	public MtmMonth(int month, int year) {
		calendar = new GregorianCalendar(year, month - 1, 1);
	}
	
	
	/**
	 * The current month
	 */
	public MtmMonth() {
		calendar = new GregorianCalendar();
		calendar.set(Calendar.DATE, 1);
	}
	
	
	/**
	 * 
	 * @return number of days in this month
	 */
	public int getNumberOfDays() {
		return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
	}
	
	
	/**
	 * Return total number of days in year which is correlative with this month
	 * @return
	 */
	public int getNumberOfDaysInYear() {
		return calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
	}
	
	
	/**
	 * 
	 * @return first day of this month
	 * 1 = Sunday
	 * 2 = Monday
	 * ...
	 */
	public int getFirstDay() {
		return calendar.get(Calendar.DAY_OF_WEEK);
	}
	
	
	/**
	 * 
	 * @return this month is the current month or not
	 */
	public boolean isCurrentMonth() {
		Calendar current = Calendar.getInstance();
		
		return (current.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)
			&& current.get(Calendar.MONTH) == calendar.get(Calendar.MONTH));
	}
	
	
	/**
	 * Getter methods
	 * @return
	 */
	public int getYear() {
		return calendar.get(Calendar.YEAR);
	}
	
	public int getMonth() {
		return calendar.get(Calendar.MONTH) + 1;
	}
	
	public void setYear(int year) {
		calendar.set(Calendar.YEAR, year);
	}
	
	public void setMonth(int month) {
		calendar.set(Calendar.MONTH, month - 1);
	}
}
